package com.enjoy.rocketmq.simple;

import com.enjoy.rocketmq.Util;
import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class LitePullConsumerSubscribe {
    public static void main(String[] args) throws Exception{

        Util.loadProperties();

        DefaultLitePullConsumer litePullConsumer = new DefaultLitePullConsumer("lite_pull_consumer");

        litePullConsumer.setNamesrvAddr(System.getProperty("nameserver.addr"));

        litePullConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);

        litePullConsumer.subscribe("TopicTest", "*");

        litePullConsumer.start();

        for (;;){
            List<MessageExt> messageExts = litePullConsumer.poll();
            System.out.printf("%s%n", messageExts);
        }

    }
}
